#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h> 
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include "drv_adc.h"

//for (channel=0;channel<4;channel++) 
//  printf("Channel %d = %.2f\n",channel,(float)ADC_Read(channel)*VREF/pow(2,10));


#define ADC_SYSFS "/sys/bus/platform/devices/at91_adc/chan"
#define VREF 3.24
#define V_PER_POINT VREF/2**10

int drv_i2cRead( int channel )
{
        int fd,adc_value;
        char filename[41];
        char buffer[5];

        sprintf(filename,"%s%d",ADC_SYSFS,channel);

        if ((fd=open(filename,O_RDONLY))<0) return -1;
	if ((read(fd,buffer,5))<0) return -1;

        adc_value = atoi(buffer);
        close(fd);

        return adc_value;
}


